package com.haipumi.listeners;

import java.util.List;

import javax.servlet.ServletContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.web.context.support.WebApplicationObjectSupport;
import com.haipumi.beans.haipumi_product;
import com.haipumi.biz.BackGoodsBiz;
import com.haipumi.utils.CommonData;

public class GoodsListener extends WebApplicationObjectSupport implements ApplicationListener<ContextRefreshedEvent> {
	
	@Autowired
    private BackGoodsBiz backGoodsBiz;
	private ServletContext servletContext;
    @Override
	protected void initServletContext(ServletContext servletContext) {
		this.servletContext=servletContext;
	}
    
    @Override
    public void onApplicationEvent(ContextRefreshedEvent ev) {
        //防止重复执行。
        if(ev.getApplicationContext().getParent() == null){
        	List<haipumi_product> list=backGoodsBiz.findAllGoods(0,100,"pid","desc");
        	servletContext.setAttribute(CommonData.APPLICATIONPRODUCTKEY, list);
        }
        
    }
 
}
